package com.itfreer.power.service.user;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.itfreer.form.dictionary.DictionaryManage;
import com.itfreer.form.dictionary.reflect.DictionaryFieldUtils;
import com.itfreer.power.dao.user.UserAuthenticationDao;
import com.itfreer.power.dao.user.UserInfoDao;
import com.itfreer.power.entity.user.UserInfoEntity;
import com.itfreer.power.entity.user.VUserInfoEntity;

/**
 * 定义用户基础信息管理类
 */
@Component("userInfoService")
public class UserInfoServiceBase implements UserInfoService {

	@Autowired
	private UserInfoDao userInfoDao;
	
	@Autowired
	private UserAuthenticationDao userAuthenticationDao;
	
	@Autowired
	private VUserInfoService vuserInfoService;
	
	/**
	 * 字典服务
	 */
	@Autowired(required = false)
	private DictionaryManage dictionaryService;
	
	/**
	 * 获取实体
	 * @param guid			唯一值
	 * @return
	 */
	@Override
	public UserInfoEntity getEntity(String guid){
		UserInfoEntity entity = userInfoDao.getEntity(guid);
		DictionaryFieldUtils.convertEntity(dictionaryService, entity);
		return entity;
	}
	
	/**
	 * 添加实体
	 * @param entity		添加实体
	 * @return
	 */
	@Override
	public VUserInfoEntity add(UserInfoEntity entity){
		entity = userInfoDao.add(entity);
		return vuserInfoService.getEntity(entity.getUserid());
	}
	
	/**
	 * 更新实体
	 * @param guid			唯一值
	 * @param entity		实体
	 * @return
	 */
	@Override
	public VUserInfoEntity update(UserInfoEntity entity){
		entity = userInfoDao.update(entity);
		return vuserInfoService.getEntity(entity.getUserid());
	}
	
	/**
	 * 删除实体
	 * @param guid			唯一值
	 */
	@Override
	public void delete(String guid){
		userInfoDao.delete(guid);
		userAuthenticationDao.delete(guid);
	}
	
	/**
	 * 指量删除实体
	 * @param guid			唯一值集
	 */
	@Override
	public void deletes(String guids){
		userInfoDao.deletes(guids);
		userAuthenticationDao.deletes(guids);
	}
}